class Solution 
{
public:
    int minSubArrayLen(int target, vector<int>& nums) 
    {
        // 1、初始化
        int n = nums.size();
        int minLength = INT_MAX;
        // 2、使用滑动窗口解决问题
        for(int left = 0, right = 0, sum = nums[0]; right < n;)
        {
            if(sum >= target) 
            {
                minLength = min(minLength, right - left + 1);
                sum -= nums[left++];
            }
            else 
            {
                if(++right < n)
                    sum += nums[right];
            }
        }
        // 3、返回值
        return minLength == INT_MAX ? 0 : minLength;
    }
};
